﻿<%@ Page Title="" Language="C#" MasterPageFile="~/User/User.Master" ClientIDMode="Static" AutoEventWireup="true" CodeBehind="JCCD_EditJC_BZX.aspx.cs" Inherits="CoolERP_Web.User.JCCD_EditJC_BZX" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="../Scripts/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<script src="../Scripts/lhgdialog/lhgcore.min.js" type="text/javascript"></script>
<script src="../Scripts/lhgdialog/lhgdialog.js" type="text/javascript"></script>
<script type="text/javascript">
    function resetXH() {
        $("#tbMXList tr").each(function (i) {
            if (i > 0)
                $(this).find("td").eq(0).text(i);
        });
    }
    function delThis(obj) {
        $(obj).closest("tr").remove();
        resetXH();
    }
    var dg;
    function selectBZX() {
        dg = new J.dialog({ id: 'select', title: '选择包装箱', page: 'SelectBZXKC.aspx', iconTitle: false, cover: true, btnBar: false, rang: true, autoSize: true, width: 1000, height: 700 });
        dg.ShowDialog();
    }
    function selMore() {
        J("#GridView1 input[type=checkbox][id=chkSel]", dg.dgDoc).each(function () {
            if ($(this).attr("checked") == true) {
                var tr = $(this).closest("tr").clone();
                var row = $("#tbGoodsInfo tr").length;
                var id = $(this).val();
                var bh = $(tr).find("[id='hidBH']").val();
                var name = $(tr).find("[id='hidMC']").val();
                var gg = $(tr).find("[id='hidGG']").val();
                var tj = $(tr).find("[id='hidTJ']").val();
                var zl = $(tr).find("[id='hidZL']").val();
                var bz = $(tr).find("[id='hidBZ']").val();
                var bzfs = $(tr).find("[id='hidBZFS']").val();
                var ck = $(tr).find("[id='hidCKMC']").val();
                var ckid = $(tr).find("[id='hidCKID']").val();
                var cw = $(tr).find("[id='hidCWMC']").val();
                var cwid = $(tr).find("[id='hidCWID']").val();
                var sl = $(tr).find("[id='hidSL']").val();
                var hasAdd = false;
                $("#tbMXList input[type=hidden][id='hidWid']").each(function () {
                    hasAdd = $(this).val() == id && $(this).closest("tr").find("[id='hidCKID']").val() == ckid && $(this).closest("tr").find("[id='hidCWID']").val() == cwid ? true : false;
                    if (hasAdd)
                        return false;
                });
                if (!hasAdd) {
                    $("<tr><td>" + row + "</td><td>" + bh + "</td><td>" + name + "<input type=hidden id='hidWid' value='" + id + "' /></td>\
                <td>" + bzfs + "</td><td>" + gg + "</td><td>" + tj + "</td><td>" + zl + "</td><td>" + bz + "</td>\
                <td><input type=text class='textbox' id='txtCount' value='' style='width:60px; text-align:center' onkeyup='txtLimit(this,0)' /></td>\
                <td>" + sl + "</td><td>" + ck + "<input type=hidden id='hidCKID' value='" + ckid + "' /></td><td>" + cw + "<input type=hidden id='hidCWID' value='" + cwid + "' /></td>\
                <td><img src='../Images/Common/btn_del0.png' onclick='delThis(this)' style='cursor:pointer' /></td></tr>").appendTo("#tbMXList");
                } 
            }
        });
        resetXH();
        dg.cancel();
    }
    function checkSubmit() {
        if (isEmpty($("#ddlDepartments").val())) {
            alert("请选择验收部门");
            return false;
        }
        if (isEmpty($("#hidStaff").val())) {
            alert("请选择验收人");
            return false;
        }
        if (isEmpty($("#ddlReason").val())) {
            alert("请选择进仓原因");
            return false;
        }
        var isOk = true;
        var idList = new Array();
        var countList = new Array();
        var ckidList = new Array();
        var cwidList = new Array();
        $("#tbMXList tr").each(function (i, item) {
            if (i > 0) {
                var wl = {
                    id: $(this).find("input[type=hidden][id='hidWid']").val(),
                    count: $(this).find("input[type=text][id='txtCount']").val(),
                    ckid: $(this).find("input[type=hidden][id='hidCKID']").val(),
                    cwid: $(this).find("input[type=hidden][id='hidCWID']").val()
                };
                if (!isEmpty(wl.id) && isEmpty(wl.count)) {
                    alert("请填写第" + i + "个包装箱的数量");
                    isOk = false;
                    return isOk;
                }
                idList[idList.length] = wl.id;
                countList[countList.length] = wl.count;
                ckidList[ckidList.length] = wl.ckid;
                cwidList[cwidList.length] = wl.cwid;
            }
        });
        if (!isOk)
            return false;
        $("#hidID").val(idList);
        $("#hidCounts").val(countList);
        $("#hidCKIDs").val(ckidList);
        $("#hidCWIDs").val(cwidList);
        if (isEmpty($("#hidID").val())) {
            alert("至少必须添加一个包装箱明细");
            return false;
        }
        return true;
    }
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td class=tbHead_L></td>
        <td class=tbHead_M><div style="text-align:center; font-size:16px"><b><asp:Literal ID="liTitle" runat=server>新增</asp:Literal>包装箱进仓单</b></div></td>
        <td class=tbHead_R></td>
    </tr>
    <tr>
        <td class=tbBody_L></td>
        <td class=tbBody_M>
            <ul class=tags style="width:95%;"><li class=liTitle><div>详细信息</div></li></ul>
            <table class="grvCSS" cellspacing="0" cellpadding=2 border="1" style="width:95%;border-collapse:collapse;">
                <tr>
                    <td width=10% style="text-align:right">验收部门：</td>
                    <td style="text-align:left; width:56%" colspan=3><asp:DropDownList ID="ddlDepartments" runat="server" CssClass="dropdown" onchange="BindStaff('ddlStaff',this.value,'请选择')"/></td>
                    <td width=10% style="text-align:right">验收人：</td>
                    <td style="text-align:left;width:24%"><asp:DropDownList ID="ddlStaff" runat="server" CssClass="dropdown" Width="150px" onchange="setStaff('hidStaff',this.value)"></asp:DropDownList>
                    <input type="hidden" runat=server id="hidStaff" /></td>
                </tr>
                <tr>
                    <td width=10% style="text-align:right">备注：</td>
                    <td style="text-align:left;" colspan=3><asp:TextBox ID="txtBZ" runat="server" CssClass="textbox" Width=90%/></td>
                    <td width=10% style="text-align:right">进仓原因：</td>
                    <td style="text-align:left;width:24%"><asp:DropDownList ID="ddlReason" runat="server" CssClass="dropdown"/></td>
                </tr>
            </table>
            <ul class=tags style="width:95%;">
                <li class=liTitle><div>明细列表</div></li>
                <li class=liRight><img onclick="selectBZX()" title="增加明细" src="../Images/Common/btn_add0.png" style="cursor:pointer" /></li>
            </ul>
            <table id="tbMXList" class=grvCSS cellpadding=0 cellspacing=0 border=1 style="width:95%;border-collapse:collapse;">
                <tr>
                    <th>序号</th><th>编号</th><th>名称</th><th>包装方式</th><th>外（长*宽*高）</th><th>体积</th><th>重量</th><th>备注</th><th>入仓数量</th><th>库存数量</th><th>仓库</th><th>仓位</th><th width=100px></th>
                </tr>            
            <asp:Repeater ID="repMXList" runat="server">
            <ItemTemplate>
                <tr>
                    <td><%# Container.ItemIndex + 1%></td><td><%# Eval("BH") %><input type=hidden id="hidWid" value='<%# Eval("WPID") %>' /></td>
                    <td><%# Eval("MC") %></td><td><%# Eval("BZFS") %></td><td><%# Eval("WChang")%>*<%# Eval("WKuan")%>*<%# Eval("WGao")%></td>
                    <td><%# Eval("TJ") %></td><td><%# Eval("ZL")%></td><td><%# Eval("BZ")%></td>                    
                    <td><input type=text class="textbox" id="txtCount" value='<%# Eval("SL") %>' style="width:60px; text-align:center" onkeyup="txtLimit(this,0)" /></td>
                    <td><%# Eval("SL")%></td><td><%# Eval("CKMC")%><input type=hidden id='hidCKID' value='<%# Eval("CKID") %>' /></td><td><%# Eval("CWMC")%><input type=hidden id='hidCWID' value='<%# Eval("CWID") %>' /></td>
                    <td><img src="../Images/Common/btn_del0.png" onclick="delThis(this)" style="cursor:pointer" /></td>
                </tr>
            </ItemTemplate>
            </asp:Repeater>
            </table>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
            <p><asp:ImageButton ID="btnSave" runat="server" ImageUrl="~/Images/Common/btn_save0.png" onclick="btnSave_Click" OnClientClick="return checkSubmit();" />&nbsp;&nbsp;
                <a href="JCCD_Query_JC.aspx?lx=1"><img src="../Images/Common/btn_back0.png" border=0 /></a>&nbsp;&nbsp;
                <asp:Label ID="labResult" runat="server" ForeColor=Red></asp:Label>
            </p></ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnSave" EventName="Click" />
            </Triggers>
            </asp:UpdatePanel>
        </td>
        <td class=tbBody_R></td>
    </tr>
    <tr>
        <td class=tbFoot_L></td>
        <td class=tbFoot_M></td>
        <td class=tbFoot_R></td>
    </tr>
</table>
<asp:HiddenField ID="hidID" runat="server" /><asp:HiddenField ID="hidCounts" runat="server" />
<asp:HiddenField ID="hidCWIDs" runat="server" /><asp:HiddenField ID="hidCKIDs" runat="server" />
</asp:Content>